package world2d;
import box2D.collision.shapes.B2CircleShape;
import box2D.collision.shapes.B2Shape;
import box2D.common.math.B2Vec2;
import box2D.dynamics.B2Body;
import box2D.dynamics.B2BodyDef;
import box2D.dynamics.B2FixtureDef;
import box2D.dynamics.B2Fixture;
import box2D.dynamics.B2World;
import data.Object2DData;
import haxe.macro.Expr.Position;
import haxe.Timer;
import openfl.Assets;
import openfl.display.Bitmap;
import openfl.display.Sprite;

/**
 * ...
 * @author Marcos Martinez
 */
class Bullet2D extends Sprite
{
	private var m_cWorld:B2World;
	private var m_cBody:B2Body;
	private var m_cFixtureDef:B2FixtureDef ;
	public var m_cKteDir:Int;
	public function new(cWorld:B2World) 
	{
		super();
		m_cWorld = cWorld;
	
	}
	
	public function create():Void
	{
		var wheelBodyDef:B2BodyDef = new B2BodyDef();
		wheelBodyDef.type = B2Body.b2_dynamicBody;
		wheelBodyDef.angularVelocity = 0.1;
		
		m_cBody = m_cWorld.createBody(wheelBodyDef);

		var cData :Object2DData = new Object2DData();
		cData.m_nName = "bullet";
		m_cBody.setUserData(cData);
		
		m_cFixtureDef = new B2FixtureDef();
		m_cFixtureDef.density = 1.0;
		m_cFixtureDef.shape =  new B2CircleShape(12);		
		
	}
	public function startMoving(nX:Float,nY:Float,nVelX:Float,nVelY:Float)
	{
		
		var wheelFixture:B2Fixture = m_cBody.createFixture(m_cFixtureDef);

		var startingVelocity:B2Vec2 = new B2Vec2(nVelX, nVelY);
		// m_cBody.m_force = new B2Vec2(100, 100);
		m_cBody.setLinearVelocity(startingVelocity);
		m_cBody.applyImpulse(new B2Vec2(nX,-1*nY), m_cBody.getWorldCenter());
		m_cBody.setPosition(new B2Vec2(nX, nY));
		
	}
	public function move():Void
	{
		

	//	this.x = m_cBody.getPosition().x;
		//this.y = m_cBody.getPosition().y;
		//trace(this.x+" : "+this.y);
	}
	
}